package com.focus.xyz.union.cases.backend;

import com.focus.xyz.core.common.annotation.Task;
import com.focus.xyz.core.common.webdriver.DriverFactory;
import com.focus.xyz.union.action.KeyWordAction;
import com.focus.xyz.core.common.listeners.TC;
import com.focus.xyz.core.utils.Constants;
import com.focus.xyz.core.utils.ExcelUtils;
import com.focus.xyz.core.utils.ProcessUtil;
import com.focus.xyz.core.utils.prop.ConfigPropInfo;
import com.focus.xyz.union.data.InsDataBean;
import com.focus.xyz.union.data.InsDataService;
import com.focus.xyz.union.pages.backend.BackMenuList;
import com.focus.xyz.union.pages.backend.ProdScope;
import com.focus.xyz.union.pages.backend.tables.MemTable;
import org.openqa.selenium.WebDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.*;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by chenmeng on 2016/4/26.
 */

public class BackAllTest extends TC {
    private static transient Logger logger = LoggerFactory.getLogger(BackAllTest.class);

    private WebDriver driver;
    private KeyWordAction action;
    private ExcelUtils eu;

    @BeforeClass
    public void beforeClass() throws Exception{
        eu = new ExcelUtils(ConfigPropInfo.TEST_DATA_DIR + ConfigPropInfo.TEST_UNION_DATA_FILE);
    }

    @Parameters({"nodeUrl","browser","userName","password"})
    @BeforeMethod(alwaysRun = true)
    public void setUp(String nodeUrl,String browser,String userName,String password) throws Exception{
        driver = DriverFactory.getDriver(nodeUrl).getBrowser(browser);
        super.init(driver);
        action = new KeyWordAction(driver);
        action.LoginBack(userName,password);
    }


    @Parameters({"browser"})
    @AfterMethod(alwaysRun = true)
    public void tearDown(String browser) {
        try{
            super.quit();
            driver.quit();
        }catch (Exception e){
            ProcessUtil.closeBrowser(browser);
        }finally {

        }
    }



    @Parameters({"memName","insDataIdx","feeRate"})
    @Task(taskName = {"DEL_PRD_SCOPE_PLAT.sql"},paras = {"param0=cimon007"})//cimon007
    @Test(description = "设置产品范围用例")
    public void SET_PROD_SCOPE_PLAT(String memName,String insDataIdx,String feeRate) throws Exception{
        BackMenuList menuList = new BackMenuList(driver,action);
        menuList.openExpandMenu("渠道会员管理","查询渠道会员");
        MemTable memTable = new MemTable(driver,action);
        memTable.search(memName);
        action.pause(1000l);
        memTable.openLink(memName,"查看产品");
        action.pause(2000l);
        InsDataBean bean = InsDataService.getInsDataById(insDataIdx);
        List<String> list = new ArrayList<String>();
        list.add(bean.getProdName());
        //设置产品范围和投放平台
        action.SetProdScopeAndPlat(list, Constants.K_AGENT);

        //设置实际服务费比例
        ProdScope prodScope = new ProdScope(driver,action);
        action.pause(1000l);
        prodScope.setFee(feeRate);//设置实际服务费为10%
        action.acceptAlert();

    }


    @Parameters({"memName","settleType"})
    @Test(description = "设置会员结算方式")
    public void SET_SETTLE_TYPE(String memName,String settleType) throws Exception{
        action.ChangeSettleType(memName,settleType);
    }

    @Parameters({"memName"})
    @Test(description = "后台审核会员")
    public void APPROVAL_MEM(String memName) throws Exception{
        BackMenuList menuList = new BackMenuList(driver,action);
        menuList.openExpandMenu("渠道会员管理","查询渠道会员");
        MemTable memTable = new MemTable(driver,action);
        memTable.search(memName);
        action.pause(1000l);
        memTable.openLink(memName,"审核");
        action.pause(2000l);
        memTable.submit("Auto-审核通过");
    }

}
